import { defineComponent, ref } from 'vue'
import useTimeExecutor from '@/hooks/useTimeExecutor'

export default defineComponent({
  setup() {
    const data = ref({})

    // 更新数据的方法
    const fetchData = async () => {
      //const res = await http.get('/api/some/data')
      data.value = {name: 'Ricky', age: 18}
    }

    // 使用hooks, 表示每隔10秒会执行fetchData去更新数据
    const { pause, play, isLoading } = useTimeExecutor({
      second: 10,
      func: fetchData
    })

    // 可自行暂停/继续更新数据
    const handleButtonClick = e => {
      e ? pause() : play()
    }

    return {
      data,
      isLoading ,
      handleButtonClick 
    }
  }
})
